package com.xca.bindingwork.repository;

import com.xca.bindingwork.entity.PetEntity;
import com.xca.bindingwork.service.PetService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class PetRepository {
    public static final String PET_BASE_URL = "https://apis.tianapi.com/";
    public static final String PET_KEY = "494dec28699ea11966d3ddf914f7cf9f";
    private static final String TAG = "PetRepository";
    private static final int PAGE_SIZE = 1;
    private static final int PAGE_NUM = 15;
    private PetService petService ;

    public PetRepository(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(PET_BASE_URL)
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build() ;
         petService = retrofit.create(PetService.class);
    }
    public Observable<PetEntity> getData(int type){
        return petService.getData(PET_KEY,PAGE_SIZE,PAGE_NUM,type)
                .observeOn(AndroidSchedulers.mainThread())
                .observeOn(Schedulers.io()) ;
    }
    public Observable<PetEntity> getData2(String name){
        return petService.getData2(PET_KEY,PAGE_SIZE,PAGE_NUM,name)
                .observeOn(AndroidSchedulers.mainThread())
                .observeOn(Schedulers.io()) ;
    }

}
